package business.action;

import java.util.List;
import model.TUser;
import business.dao.UserDAO;
import business.factory.DAOFactory;

public class QueryAction extends BaseAction {

	private String queryText;
	
	private String errorsText;
	private String backurl;
	private String seccessText;
	
	public String getQueryText() {
		return queryText;
	}

	public void setQueryText(String queryText) {
		this.queryText = queryText;
	}

	
	public String getErrorsText() {
		return errorsText;
	}

	public String getBackurl() {
		return backurl;
	}

	public String getSeccessText() {
		return seccessText;
	}

	/**
	 * @return
	 */
	public String execute() {
	
		if(queryText==null || queryText.trim().equals("")){
			 UserDAO vdao =new DAOFactory().getUserDAO();
				List<TUser> userinfo =vdao.getTuser();				
				request.setAttribute("userinfo", userinfo);//将值存在userinfo里
				
				for(TUser userinfos : userinfo){//循环输出测试
				System.out.println("全部"+userinfos.getUserid()+userinfos.getUsername());
				}	
				seccessText = "查询全部";
				return SUCCESS;
		}else if(queryText!=null) {
			UserDAO ddao = new DAOFactory().getUserDAO();
			List<TUser> userinfo =ddao.getTuserByuserid(queryText);		
			System.out.print(queryText);
			request.setAttribute("userinfo", userinfo);	
			for(TUser userinfos : userinfo){//循环输出测试
				System.out.println("全部"+userinfos.getUserid()+userinfos.getUsername());
				}	
				seccessText = "根据姓名查询";
				return SUCCESS;
				
		}else {
			errorsText = "无该用户";
			return ERROR;
		}
		
		
	
	}
}